import request from '@/utils/request'
import type { PaginatedResult, PaginationQuery } from '@/types/common'
import type {
  Student,
  StudentCreatePayload,
  StudentUpdatePayload,
  Teacher,
  TeacherCreatePayload,
  TeacherUpdatePayload
} from '@/types/users'

export type { Teacher }

export const getStudentList = (params?: PaginationQuery) =>
  request.get<PaginatedResult<Student>>('/api/v1/students/list', { params })

export const createStudent = (payload: StudentCreatePayload) =>
  request.post<Student>('/api/v1/students/create', payload)

export const updateStudent = (id: number, payload: StudentUpdatePayload) =>
  request.put<Student>(`/api/v1/students/${id}`, payload)

export const deleteStudent = (id: number) =>
  request.delete(`/api/v1/students/${id}`)

export const getTeacherList = (params?: PaginationQuery) =>
  request.get<PaginatedResult<Teacher>>('/api/v1/teachers/list', { params })

export const createTeacher = (payload: TeacherCreatePayload) =>
  request.post<Teacher>('/api/v1/teachers/create', payload)

export const updateTeacher = (id: number, payload: TeacherUpdatePayload) =>
  request.put<Teacher>(`/api/v1/teachers/${id}`, payload)

export const deleteTeacher = (id: number) =>
  request.delete(`/api/v1/teachers/${id}`)
